class ProductCommentsController < ApplicationController
  # GET /product_comments
  # GET /product_comments.xml
  def index
    @product_comments = ProductComment.find_all_by_product_id(params[:product_id]).paginate(:page => params[:page],
                    :per_page => 2)

    @product_comment = ProductComment.new
    @product = Product.find(params[:product_id])
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @product_comments }
    end
  end

  def create
    @product_comment = ProductComment.new(params[:product_comment])
    @product_comment.product_id = params[:product_id]
    respond_to do |format|
      if @product_comment.save
        flash[:notice] = 'ProductComment was successfully created.'
        format.html { redirect_to( product_product_comments_path(params[:product_id])) }
        format.xml  { render :xml => @product_comment, :status => :created, :location => @product_comment }
      else
        format.html { render new_product_product_comment_path( @prodcut_contact.product, @prodcut_contact) }
        format.xml  { render :xml => @product_comment.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /product_comments/1
  # PUT /product_comments/1.xml
  def update
    @product_comment = ProductComment.find(params[:id])

    respond_to do |format|
      if @product_comment.update_attributes(params[:product_comment])
        flash[:notice] = 'ProductComment was successfully updated.'
        format.html { redirect_to(@product_comment) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @product_comment.errors, :status => :unprocessable_entity }
      end
    end
  end

end
